﻿using System;
using System.Windows.Forms;
using ApplicationGenerator.BusinessModule.Interfaces;

namespace ApplicationGenerator.CommonForms.Forms
{
    public partial class SelectModelFieldForm : Form
    {
        public string Path
        {
            get;
            private set;
        }

        public SelectModelFieldForm(IMetaModel metaModel)
        {
            InitializeComponent();

            modelHierarchyTree1.MetaAdapter = metaModel;
            modelHierarchyTree1.InitializeTree();
        }

        private void buttonSelect_Click(object sender, EventArgs e)
        {
            if (!modelHierarchyTree1.IsSelectedNode())
            {
                MessageBox.Show("Nie wybrano pola z drzewa modelu.", "Błąd walidacji");
                return;
            }

            //if (!AreExpectedTypes(modelHierarchyTree1.GetSelectedFieldType(), _baseMappedControl.GetType()))
            //{
            //    MessageBox.Show("Wybrane pole jest nieodpowiedniego typu dla danej kontrolki.", "Błąd walidacji");
            //    return;
            //}

            string selectedField = modelHierarchyTree1.GetSelectedField();
            if (selectedField == null)
            {
                MessageBox.Show("Nie wybrano pola z drzewa modelu.", "Błąd walidacji");
                return;
            }

            Path = selectedField;

            DialogResult = DialogResult.OK;
            this.Close();

        }

        private bool AreExpectedTypes(Type modelFieldType, Type mappedControlType)
        {
            //ControlTypeComparer typeComparer = new ControlTypeComparer();
            //return typeComparer.AreValidTypes(mappedControlType, modelFieldType);
            return true;
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            this.Close();
        }


    }
}
